/*-------------------------------------------------------------------------

***************** Modification History ***********************************
 * @doc BATCH
 * @module batch.h |
 * Header file for batch fucntions.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   : Monique Brown
 * <nl>Notes       : NOVA batch.h file

$Log: /SoftPay/SPK2SIM/Source/Include/batch.h $
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#ifndef VSBATCH_H
#define VSBATCH_H

#define BAT_EOF            100        /* End of batch file reached  */
#define BAT_INIT           101        /* Open the batch record file */
#define BAT_GET_DATA       102        /* Get the Next batch record  */
#define BAT_FINISH         103        /* Close the batch record file*/
#define BAT_UPDATE         104        /* Update batch record */

#define CLEAR_HOST      1991
#define CLEAR_BATCH     1987

#define KEY_INV_NUM         0x0001      /* Invoice number is the key  */
#define KEY_SHIFT           0x0002      /* Shift # is the key */
#define KEY_ACC_NUM         0x0004      /* Last 5 digits of acct # is the key */
#define KEY_SVR_ID          0x0008      /* Server/Clerk Id is the key */
#define KEY_AMT             0x0010      /* Transaction amount is the key */
#define KEY_ORG_STAN        0x0020      /* ORG_STAN is the key  */
#define KEY_CURRENCY        0x0040      /* Currency is the key  */
#define KEY_HOST            0x0080      /* Host Number is the key */
#define KEY_OFFLINE         0x0100      /* Offline Flag is the key */
#define KEY_VOIDED          0x0200      /* Voided Flag is the key */
#define KEY_UPLOADED        0x0400      /* Uploaded Flag is the key */
#define KEY_ALL_RECS        0x0800      /* All records match */
#define KEY_SEARCH_LAST     0x1000      /* Last  record in a linked list match */
#define KEY_SEARCH_FIRST    0x2000      /* First record in a linked list match */

/* Batch record update actions based on an index */

#define ACT_UPLOAD      301        /* Update the upload flag     */
#define ACT_VOID        302        /* Update Batch - Void trans  */
#define ACT_ADJUST      303        /* Update Batch - Adj trans   */
#define ACT_CHAININV    304        /* Add inv. of transaction modifying this rec */
#define ACT_TIP_ADJUST  305        /* Update Batch - Tip Adj trans */   /*kcc */

/* Transaction results */

#define CANCELLED		0
#define AUTHORIZED		1
#define REFERRAL		2
#define DECLINED		-1
#define COMM_ERROR		-2

/* Batch record and key data structure */

typedef struct TagBATCH_REC
{
    short   inCode;                                /* Trans Code */
    short  inOrgCode;                             /* Original Trans Code  */
    short  inType;                                /* Transaction type */
    long lnBaseTransactionAmount;               /* The base transaction amount, such as a SALE. */
    long lnOrigTotalTransactionAmount;          /* Original Total Amount */
    long lnOldTotalTransactionAmount;           /* Original Total Amount */
    long lnTipAmount;
    long lnOldTipAmount;
    long lnTaxAmount;
    long lnDualAmount;
    long lnCashBackAmount;
    long lnSChgAmount;
    long lnSTAN;                                /* Stan's the man...        */
    char szPAN[PAN_SIZE + 1];                     /* Account number */
    char szExpDate[EXP_DATE_SIZE + 1];            /* Expiration date */
	char szIssueNumber[ISSUER_NUM_SIZE + 1];
    char szAuthCode[AUTH_CODE_SIZE + 1];          /* Auth Code           */
    char szRespCode[RESP_CODE_SIZE + 1];          /* Response Code       */
    int  inTranCardType      ;                    /* Credit, Debit, Loyal  */
    char szDate[DATE_SIZE + 1];
    char szTime[TIME_SIZE + 1];
    long lnMessage;                               /* Message associated w/ transaction. */
    short  inPrintOption;                           /* Print Option Flag (also in TCT) */
                                                  /* 0=None,1=Prompt,2=Cust,3=Merch,4=Both */
    short  inCDTIndex;                  			  /* Currently loaded CDT iff card host */

    short  inLCTIndex;                  			  /* Language index for receipt */
    short  inMerchantIndex;						  /* Merchant index */

    short inNumberOfAdjusts;           			  /* number of adjustments made to transactions */
    short inNumberOfTipAdjusts;        			  /* number of Tip adjust made to transactions */
    short inTransactionResult;					  /* Authorized, Declined or Cancelled */

    /* ECI Information */
    char chECI;                       			  /* Electronic Commerce Indicator */
    char szTranAbbrev[TRT_ABBREV_SIZE + 1];  	  /* Tran abbrev for reports */

#ifdef PAYMENT_DEFINED                              /* Variables for the use of Payments			*/
    short inInstallmentType;
    short inInstallments;
    short inPlan;
    long lnDepositAmount;
    long lnAmountPerInstallment;
#endif /* PAYMENT_DEFINED */

	char szStartDate[EXP_DATE_SIZE + 1];
	int  inChipStatus;				/* 0 NOT_USING_CHIP, 1 EMV_CARD, 2 EMV_EASY_ENTRY_CARD*/
											        /*  Linked List variables for new batch records
													    per Adjust/Void transactions */
    long	lnForwardLinkInvNum;					/*  Inv # batch record forward link */
    long	lnBackLinkInvNum;						/*  Inv # batch record backward link */
    long	lnOrgInvNum;							/*  Original Transaction Invoice # */

    unsigned fManual            : 1;                /*  Manual/Swipe      */
    unsigned fTaxEntered        : 1;                /*  Tax has been prompted for or Calculated */
    unsigned fTipEntered        : 1;                /*  Tip has been prompted for or Calculated */
    unsigned fDualEntered       : 1;                /*  Dual Currency has been prompted for or Calculated */
    unsigned fCloseTabSameCard  : 1;                /*  Close Tab tran with same card */
    unsigned fCloseTabNewCard   : 1;                /*  Close Tab tran with new card */
    unsigned fComputeOverage    : 1;                /*  Overage Applied flag*/
    unsigned fDoNotUploadRec	: 1;				/*  Do Not Upload Batch Record flag */
    unsigned fLastTranUploaded	: 1;				/*  Last Transaction Uploaded flag */
	unsigned fWebTran           : 1;                /*  Web Tran 0=no, 1=yes */
	                                                //  Optional Field bits
	unsigned fRoomNum           : 1;                //  Room Number stored
	unsigned fCustNum           : 1;                //  Customer Number stored
	unsigned fT1Data            : 1;                //  Track 1 Data stored
	unsigned fT2Data            : 1;                //  Track 2 Data stored
	unsigned fCHolder           : 1;                //  Card holder name stored

	//  Below Fields not saved as part of the Batch Data Structure
    unsigned char *pchHostData;					    /*  Pointer to Host specific batch data */

    // Optional fields not always stored in the batch record
    char szRoomNum[ROOM_NUM_SIZE + 1];

    char szCustNum[REF_CUST_SIZE + 1];              /*  CustNo Purch Card Support */

    char stT1Data[TRACK1_SIZE +1];                  /*  Track 1 bare format */
    char stT2Data[TRACK2_SIZE +1];                  /*  Track 2 bare format */
    char szCHolder[CHOLDER_SIZE + 1];               /*  Card holder name */

} BATCH_REC;

typedef struct TagOPTIONAL_BATCH_REC
{
	//  Below Fields not saved as part of the Batch Data Structure
    unsigned char *pchHostData;					    /*  Pointer to Host specific batch data */

    // Optional fields not always stored in the batch record
    char szRoomNum[ROOM_NUM_SIZE + 1];

    char szCustNum[REF_CUST_SIZE + 1];              /*  CustNo Purch Card Support */

    char stT1Data[TRACK1_SIZE +1];                  /*  Track 1 bare format */
    char stT2Data[TRACK2_SIZE +1];                  /*  Track 2 bare format */
    char szCHolder[CHOLDER_SIZE + 1];               /*  Card holder name */

} OPTIONAL_BATCH_REC;

typedef int (*PFI_PUC_PBR)(unsigned char *, BATCH_REC *);

//#define MAX_HOST_DATA_FLEXI_SZ		500
//spqalog 013 & 014 increase size to accommodate errors when calling inStoreBatchFieldData
#define MAX_HOST_DATA_FLEXI_SZ		2000

#define NO_OPTIONAL_BATCH_FIELDS     (5)      // # of optional fields in BATCH_REC

#define BDS_FIELD_ROOM_NUM                        1
#define BDS_FIELD_CUST_NUM                        2
#define BDS_FIELD_T1_DATA                         3
#define BDS_FIELD_T2_DATA                         4
#define BDS_FIELD_CHOLDER                         5

#define BDS_ROOM_NUM                            0x9901
#define BDS_CUST_NUM                            0x9902
#define BDS_T1_DATA                             0x9903
#define BDS_T2_DATA                             0x9904
#define BDS_CHOLDER                             0x9905

#define SIZE_BATCH_REC                          sizeof(BATCH_REC)
#define SIZE_OPTIONAL_BATCH_REC                 sizeof(OPTIONAL_BATCH_REC)

#define SIZE_BATCH_DATA                         (SIZE_BATCH_REC-SIZE_OPTIONAL_BATCH_REC)

typedef struct TagBATCH_KEY
{
    long    	lnRecNum;                           /* Compulsary for DBFM      */
    long    	lnInvNum;                           /* Invoice number as long   */
    char    	chShift;                            /* Shift Number             */
    long    	lnLast4;                            /* Last 4 digits as long    */
    char    	szClerkId[CLERK_ID_SIZE + 1];       /* Clk/Svr ID               */
    long    	lnTotalOfTransactionAmount;         /* Transaction amount       */
    long    	lnOrgSTAN;                          /* The original Stan the man... */
    short     	inCurrencyIndex;                    /* Currency index for batch record */
    short     	inBatchHostIndex;                   /* Index to this->Batch */
    short     	inHDTIndex;                   		/* Index to this->host */
    unsigned 	fOffline       : 1;                 /* Is this Offline?  */
    unsigned 	fVoided        : 1;                 /* Voided flag */
    unsigned 	fUploaded      : 1;                 /* Uploaded flag */
#ifdef CASHCARD_DEFINED		//meca 20041023 -- fixed from cashcard O3750 -- for duplicate copy of receipt (card type) -- start
    char		szCardType[CLABEL_SIZE+1];
#endif	//CASHCARD_DEFINED		//meca 20041023 -- fixed from cashcard O3750 -- for duplicate copy of receipt (card type) -- end

} BATCH_KEY;

#define SIZE_BATCH_KEY         sizeof(BATCH_KEY)

typedef struct TagBATCH_SKEY {
    int         (*compare_func) ();
    short         inKeyIdx;
    BATCH_KEY   BKey;
} BATCH_SKEY;

typedef struct TagBATCH_DATA_INFO {

	short		inMaxRecSize;

} BATCH_DATA_INFO;

#endif  /* VSBATCH_H */
